package net.huashitong.supervision.task.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.supervision.task.dao.TaskEndDateDao;
import net.huashitong.supervision.task.entity.TaskEndDate;
import net.huashitong.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TaskEndDateService extends StringPKService<TaskEndDate> {
    @Autowired
    private TaskEndDateDao dao;
    @Autowired
    private SysTableService tableService;

    @Override
    protected BaseDao<TaskEndDate, String> getDao() {
        return dao;
    }


    @Override
    protected void beforeSave(TaskEndDate obj) {
        String s = tableService.updateMaxSysId("t_task_enddate", null);
        obj.setSysId(s);
    }

    public String getEndDate(String taskuniId)
    {
        TaskEndDate taskendDate = dao.getTaskendDate(taskuniId);

        String endDate = taskendDate.getEndDate();
        return endDate;
    }


    /**
     * 判断是否过期
     * 1 没过期
     * 0 过期了
     *
     */
    public  int isOverdue(String taskunitId){
        String endDate = getEndDate(taskunitId);
        String currentDate = DateUtil.getCurrentDate();
        int tem = endDate.compareTo(currentDate);//负数代表过期了
        if(tem>0){
            return 1;
        }
        return  0;
    }

}
